home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Eagles Nest BBS 8
/
Eagles_Nest_Mac_Collection_Disc_8.TOAST
/
Developer Tools⁄Additions
/
InsideBa1994
/
InsideBasic-94
/
IB 94
/
BTerm
/
BTerm1.6bas
next >
Wrap
Text File
|
1991-09-24
|
73KB
|
2,165 lines
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' A complete terminal program in ZBASIC 5.01
' BTerm Copyright 1991 by Mel Patrick
' All rights reserved
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
'
DEF OPEN="CNFGBTRM"
WINDOW OFF:COORDINATE WINDOW
DEF MOUSE=-1:CURSOR 4:WIDTH -2
'
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
'Resources
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
Hndl& = FN GETRESOURCE(CVI("BTRM"),0)
LONG IF Hndl& = 0
ResRef = FN OPENRESFILE("BTerm1.res")
END IF
'
'
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
'Equates
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
DIM T,L,B,R:' Generic rectangles
DIM My,Mx,GlobalY,GlobalX,LocalY,LocalX:' Mouse points
DIM Ft,Fl,Fb,Fr,Fy,Fx:' Rect & point for functions
DIM Mt,Ml,Mb,Mr:' for auto cursor functions
True = NOT(False)
DIM KeyRecord(7):' Record structure for keyboard map
' Record structure for font dimensions
DIM FAsc,FDes,FWid,FLead,Fht
DIM 40 BtnName$,40 CtrlTitle$:' Simple string for button names
DIM 1 Cr$:Cr$= CHR$(13):' Return character
DIM 1 Q$ :Q$ = CHR$(34):' Quote mark
DIM PenSpecs$:' Holds current pen data
'
' Record structure for sysEnvirons procedure
DIM EnvVersion,MachineType,SystemVersion,Processor
DIM HasFPU,KeyBoardType,AtDrvrVersNum,SysVRefNum
' Request environment info from toolbox
OsErr = FN SYSENVIRONS(1,VARPTR(EnvVersion))
ColorQD = HasFPU AND 1
'
DIM Red,Green,Blue:' RGB record
DIM RFore,GFore,BFore:' Structure to hold foreground RGB
DIM RBack,GBack,BBack:' Structure to hold background RGB
'
DIM ScrnT,ScrnL,ScrnB,ScrnR:' Rect of main screen
CALL GETWMGRPORT(WMgrPort&):' Ptr to desktop grafport
' Move its rect to my structure
BLOCKMOVE WMgrPort&+8,VARPTR(ScrnT),8
'
Arrow = 0:IBeam = 1:' Cursors
CrossHair = 2:Plus = 3
Watch = 4:Hand = 1000
Ball = 1001:' my spinning beach ball cursor
'
ButtonAct = 1:FieldAct = 2:' Dialog events
WindowAct = 3:CloseAct = 4
RefreshAct = 5:ReturnAct = 6
TabAct = 7:ZoomInAct = 8
ZoomOutAct = 9:ShTabAct = 10
ClearAct = 11:LeftAct = 12
RightAct = 13:UpAct = 14
DownAct = 15:KeyAct = 16
DiskAct = 17
'
'
DIM Stak(20):' My event stack
StakHi = 20:' Max items on stack
SP = 0:' Stack pointer
OpenEvent = 1:' Request to open a window
CloseEvent = 2:' Request that a window be closed
MenuEvent = 3:' Request that menu be de-highlighted
BreakEvent = 4:' Request that program be terminated
'
COMWIN = 1
TSWIN = 2
CSWIN = 3
SNDWIN = 4
RECWIN = 5
PROSET=6
ABTWIN = 7
'
DATA 2,1,2,1,2,1,0,0,0,2:' Terminal settings TBut
DATA 1,1,2,1,1,1,1,1,2,2,1,2,1,1,2,1:' Uart settings Cbut
DATA 1,1,2,1,1,2,1:' Transfer Settings Pbut
'
DIM Tbut(10):FOR T=1 TO 10:READ Tbut(T):NEXT T: ' PROGRAMS DEFAULT TERM SETTINGS
DIM Cbut(16):FOR T=1 TO 16:READ Cbut(T):NEXT T: ' Program in Com settings
DIM Pbut(7):FOR T=1 TO 7:READ Pbut(T):NEXT T:' program in transfer settings
DIM Hold(16):' For holding temp items in CLICK dialogs
'
DIM Paramblock$,PBlock$:' used for file location and finder info
DIM 82 Screen$(75):' for holding screen data in case of redraw
'
RECV$=STRING$(200," "):' xmodem buffer for incoming/out going
'
Soh=1:Ack=6:Can=24:Nak=21:Eot=4:' used to signal xmodem routines
CtrlS=19:CtrlQ=17:' codes for PAUSE and RESUME
GFFont=4:GFSize=9:GFFace=0:GFMode=1
SerPort=-1:Baud=2400:Parity=0:StopBit=0:WordLen=1:BufLen=1029
'
Control$=STRING$(32,CHR$(0)):' set all control values to NULL
MID$(Control$,7,1)=CHR$(7):' allow the BELL sound
MID$(Control$,8,1)=CHR$(8):' allow a backspace value
MID$(Control$,9,1)=CHR$(9):' allow a TAB value
MID$(Control$,10,1)=CHR$(10):' allow line feeds
MID$(Control$,13,1)=CHR$(13):' allow carriage returns
'
ON ERROR GOSUB 65535:' enable disk error trapping
'
GOSUB "UART":' setup default uart stuff
Cur$=" ":' default to graphic cursor
TMode=5:' used for doing the backspace with the cursors
ChrCnt=0:' used for counting characters for autolinefeed on column full.
CntMax=80:Y=0:' columns per line on screen
CapFlag=0:' turn off the text capture flag
SendFlag=0:' text file sending flag off
Wink=0:EnBlink=1:' current cursor state (0=off,1=on)
Flag=1:' disable loading from finder
DEF OPEN"CNFGBTRM"
GOSUB "Read_Config":' read in the default settings first
Flag=0:' always reset this so we bypass the reading routine
GOTO"Queue"
'
'
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
'Functions
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
'
' T/F - Color is >2 bits deep?
'
LONG FN CheckColor
LONG IF ColorQD
CkClrPtr& = PEEK LONG(PEEK LONG(&H0CC8))
Boolean = PEEK LONG(CkClrPtr&+42)>129
XELSE
Boolean = False
END IF
END FN = Boolean
'
' Set the font and calc its height
'
LONG FN GetFht(GFFont,GFSize,GFFace,GFMode)
TEXT GFFont,GFSize,GFFace,GFMode
CALL GETFONTINFO(FAsc)
END FN = FAsc+FDes+FLead
'
' Capture offset values from handles
'
DEF FN GetWord(GWHndl&,GWOffSet)=PEEK WORD(PEEK LONG(GWHndl&)+GWOffSet)
DEF FN GetLong&(GLHndl&,GLOffSet)=PEEK LONG(PEEK LONG(GLHndl&)+GLOffSet)
'
'
' Place an integer on my event stack
'
LONG FN Push(PushVal)
IF SP+1>StakHi THEN SP=StakHi-1
SP = SP + 1
Stak(SP) = PushVal
END FN
'
' Remove an integer from my stack
'
LONG FN Pop
LONG IF SP
PopVal = Stak(SP)
SP = SP - 1
XELSE
PopVal = 0
END IF
END FN = PopVal
'
' Refresh a window without bringing it forward
'
LONG FN Format(Wnd2Format)
LONG IF Wnd2Format
OldOutPutWnd = WINDOW(1)
WINDOW OUTPUT Wnd2Format
GOSUB"Format Wnd"
IF OldOutPutWnd THEN WINDOW OUTPUT OldOutPutWnd
END IF
END FN
'
' Locate a button by name
'
LONG FN FindBtn&(BtnName$)
FndBtnHndl&=PEEK LONG(WINDOW(14)+140)
DO
CALL GETCTITLE(FndBtnHndl&,CtrlTitle$)
LONG IF BtnName$<>CtrlTitle$
FndBtnHndl&=PEEK LONG(PEEK LONG(FndBtnHndl&))
END IF
UNTIL BtnName$=CtrlTitle$ OR FndBtnHndl&=0
END FN = FndBtnHndl&
'
' Draw a frame around a button
'
LONG FN FrameBtn(BtnName$)
FrBtnHndl&=FN FindBtn&(BtnName$)
LONG IF FrBtnHndl&
BLOCKMOVE PEEK LONG(FrBtnHndl&)+8,VARPTR(Ft),8
CALL INSETRECT(Ft,-4,-4)
PEN 3,3,1,8,0
CALL FRAMEROUNDRECT(Ft,16,16)
CALL PENNORMAL
END IF
END FN
'
'
' Change cursor according to mouse position
'
LONG FN AutoCursor(Fy,Fx)
ACResult = Arrow
LONG IF WINDOW(0): ' if we have an active window
ACHndl& = TEHANDLE(WINDOW(0))
LONG IF ACHndl&
BLOCKMOVE PEEK LONG(ACHndl&),VARPTR(Ft),8
IF FN PTINRECT(Fy,Ft) THEN ACResult = IBeam
END IF
ACPort& = WINDOW(14)
LONG IF ACPort&
LONG IF FN FINDCONTROL(Fy,ACPort&,ACHndl&)
ACResult = Hand
END IF
END IF
LONG IF WINDOW(0)=SNDWIN OR WINDOW(0)=RECWIN:' works on send/rec window only
LONG IF FN PTINRECT(Fy,Mt)
IF CurStep=>4 THEN CurStep=0
ACResult=Ball+CurStep:CurStep=CurStep+1
XELSE
ACResult=Arrow:' else return to default cursor
END IF
END IF
END IF
END FN = ACResult
'
'
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Queue"
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
GOSUB"Initialize":' Execute set-up routines
FLUSHEVENTS:' Remove any events since startup
ON DIALOG GOSUB"Dialog"
ON MOUSE GOSUB"Mouse"
ON MENU GOSUB"Menu"
ON TIMER (1) GOSUB"Blink"
CURSOR Arrow:' Restore arrow cursor
'
'
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Loop"
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
'
DIALOG ON :MOUSE ON :MENU ON :TIMER ON
DIALOG OFF:MOUSE OFF:MENU OFF:TIMER OFF
'
LONG IF Abort=False AND WINDOW(0)=RECWIN
LONG IF LOF(SerPort):' check for chars in buffer
READ #SerPort,RX$;1:' read only if we received something
GOSUB "Xmodem_Receive":' go figure out where we are in routine
END IF
END IF
'
LONG IF Abort=False AND WINDOW(0) = SNDWIN:' see if transmit active
ON Xmit_Step GOSUB "Wait_Start","Send_Data","Verify","Done","Wait_Ack"
END IF
'
WHILE LOF(SerPort) AND WINDOW(0) = COMWIN
BuffCount=LOF(SerPort):' gets # of characters in the serial buffer
SELECT Pause:' see if we are in a buffer overrun condition
CASE True:' if yes, then check to see if we have enough room now
IF BuffCount-1<50 THEN PRINT #SerPort,CHR$(CtrlQ):Pause=False
CASE False:' else see if we are close to full
IF BuffCount>800 THEN PRINT #SerPort,CHR$(CtrlS);:Pause=True
END SELECT
READ #SerPort,RX$;1:' read only if window active
GOSUB "RECV1"
WEND
'
'
' Handle events on my stack
'
WHILE SP:' Is the stack pointer above zero?
MyEvent=FN Pop:' Pop the event from the stack
SELECT MyEvent:' React to the event
CASE OpenEvent:' Request to build a window
GOSUB"Build"
'
CASE CloseEvent:' Request to close a window
Wnd2Close = FN Pop:' Pop # of window to close from stack
' Bring it to the front for the capture routines
IF WINDOW(0)<>Wnd2Close THEN WINDOW Wnd2Close
GOSUB"Capture":' Capture data before closing
'
WINDOW CLOSE Wnd2Close:' Close it
'
CASE BreakEvent:' Request to terminate
LONG IF WINDOW(0)
' Close open windows 1st to handle list/region disposal
FN Push(BreakEvent)
FN Push(WINDOW(0))
FN Push(CloseEvent)
XELSE
PleaseTerminate=True
END IF
'
END SELECT:' End of event handlers
' Cont while events remain on my stack
IF PleaseTerminate=True THEN "Break"
WEND
'
LONG IF SendFlag=1:' see if sending a text file to remote
LONG IF NOT EOF(3):' loop til end of file
SELECT More
'
CASE 1:' check for the end of file
LINE INPUT #3,Dsk$:More=0:DskLen=LEN(Dsk$):Cpos=1
IF DskLen=255 THEN Crflag=0 ELSE Crflag=1:' cr on full line
'
CASE 0
PRINT #SerPort,MID$(Dsk$,Cpos,1);:' send to modem
Cpos=Cpos+1
LONG IF Cpos>DskLen
More=1
IF Crflag THEN PRINT #SerPort,Cr$;:' send cr on partial line
END IF
'
END SELECT
XELSE
LONG IF More=0
PRINT #SerPort,MID$(Dsk$,Cpos,1);:' send to modem
Cpos=Cpos+1
LONG IF Cpos>DskLen
More=1
IF Crflag THEN PRINT #SerPort,Cr$;:' send cr on partial line
END IF
XELSE
ProHndl&=FN GETMHANDLE(130)
CALL SETITEM(ProHndl&,1,"Send Text...")
CLOSE #3:SendFlag=0
END IF
END IF
END IF
'
'
' Set cursor by mouse position
'
OldCsr=NewCsr:' Save the old cursor
NewCsr=Arrow:' Reset new cursor to arrow
CALL GETMOUSE(My):' Where is the mouse?
NewCsr=FN AutoCursor(My,Mx):' Let the FN tell us
' If the cursor has changed…
IF NewCsr<>OldCsr THEN CURSOR NewCsr
'
GOTO"Loop"
'
'
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Dialog"
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
Act=DIALOG(0):Ref=DIALOG(Act)
'
LONG IF Act=CloseAct
LONG IF Ref=RECWIN:' see if transfer cancelled by user
GOSUB "Clear_Line":' send out cancel bytes first
Abort=True:' set flag so we bypass receive routine
FN Push(RECWIN):FN Push(CloseEvent):' close receive window
LONG IF RecBlock=1
RETURN
XELSE
CLOSE #1:KILL MacName$,Vol%:RETURN
END IF
END IF
LONG IF Ref=SNDWIN:' see if cancel wanted from SEND window
GOSUB"Clear_Line"
FN Push(SNDWIN):FN Push(CloseEvent):Abort=True
RETURN
END IF
LONG IF Ref=COMWIN:' see we they want to quit the application?
FN Push(BreakEvent):' if so then we insert a QUIT to shell as well
END IF
FN Push(Ref):FN Push(CloseEvent):' always close this window first
RETURN
END IF
'
IF Act=RefreshAct THEN FN Format(Ref):RETURN
'
IF Act=ClearAct THEN EDIT FIELD Ref,"":RETURN
'
LONG IF Act=WindowAct
GOSUB"Capture"
WINDOW Ref
RETURN
END IF
'
LONG IF WINDOW(0) = COMWIN
IF Ref=3 THEN Ref=13:' change the ENTER key to RETURN key
IF Act=KeyAct THEN RX$=CHR$(Ref):CALL OBSCURECURSOR:' always turn it off
SELECT
CASE RX$=CHR$(8) AND Tbut(6)=2
RX$=CHR$(127)
PRINT #SerPort,RX$;
RX$=CHR$(8)
CASE RX$=CHR$(8) AND Tbut(5)=2
PRINT #SerPort,RX$;
CASE RX$<>CHR$(8)
PRINT #SerPort,RX$;
END SELECT
IF RX$=CHR$(13) AND Tbut(9)=1 THEN PRINT #SerPort,CHR$(10);
IF Tbut(7)=1 THEN GOSUB "RECV"
RETURN
END IF
'
LONG IF WINDOW(0) = TSWIN: ' Terminal Settings Window Dialogs
LONG IF Act=ButtonAct
SELECT Ref
CASE 1
GOSUB "FNT9"
CASE 2
GOSUB "FNT12"
CASE 3
GOSUB "BLK"
CASE 4
GOSUB "UL"
CASE 5
GOSUB "BCK"
CASE 6
GOSUB "DEL"
CASE 7
GOSUB "LOC"
CASE 8
GOSUB "REM"
CASE 9
GOSUB "LF"
CASE 10
GOSUB "Close Tset"
CASE 11
GOSUB "CanTset"
CASE 12
GOSUB "Toggle Blink"
END SELECT
RETURN
END IF
RETURN
END IF
'
LONG IF WINDOW(0) = CSWIN: ' Communications Settings Dialogs
LONG IF Act=ButtonAct
SELECT Ref
CASE <=7
GOSUB "Change Baud"
CASE 8,9
GOSUB "Change WordLength"
CASE 10,11
GOSUB "Change StopBits"
CASE 12,13,14
GOSUB "Change Parity"
CASE 15,16
GOSUB "Change Port"
CASE 17
GOSUB "Close Cset"
CASE 18
FOR T=1 TO 16:Cbut(T)=Hold(T):NEXT T:' Restore original values
GOSUB "Close Cset"
END SELECT
END IF
RETURN
END IF
'
LONG IF WINDOW(0) = SNDWIN
'nothing happens in this window, its all automatic for file xfer
END IF
'
LONG IF WINDOW(0) = RECWIN
'nothing happens in this window, its all automatic for file xfer
END IF
'
LONG IF WINDOW(0) = PROSET
LONG IF Act = ButtonAct
SELECT Ref
CASE 1,2,3,4:' change type and creator
GOSUB "Update Text"
CASE 5,6:' change type of xmodem transfer
GOSUB "Update TransType"
CASE 7
GOSUB "Update MacBin"
CASE 8:' OK button used
GOSUB "Close TranSet"
CASE 9
GOSUB "CanTranSet":' cancel settings made
END SELECT
END IF
LONG IF Act=KeyAct
SELECT Ref
CASE 3
GOSUB "Close TranSet"
END SELECT
END IF
END IF
'
LONG IF WINDOW(0) = ABTWIN
LONG IF Act = ButtonAct
SELECT Ref
CASE 1:' OK button used
GOSUB "Close About"
END SELECT
END IF
LONG IF Act=KeyAct
SELECT Ref
CASE 13,3
GOSUB "Close About"
END SELECT
END IF
END IF
RETURN
'
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Mouse"
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
Mact=MOUSE(0):Mx=MOUSE(1):My=MOUSE(2)
'
RETURN
'
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' Receive Subroutines
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Xmodem_Receive"
LONG IF Recv_Step=1
Recv_Step=2:' soon as we receive something go!
GOSUB"INIT_CRC":' set the crc/CheckSum calcs to 0 first
GOSUB"INIT_CHECKSUM":' initialize checksum routine
GOSUB"Show_Status":' show we are receiving data now...
END IF
'
SELECT Recv_Step
CASE 2:' see if we are receiving the block
IF Count>2 THEN MID$(RECV$,Count-2,1)=RX$
LONG IF Count=0:' checks for the first character received
LONG IF RX$=CHR$(Eot)
PRINT #SerPort,CHR$(Ack):Recv_Step=8:BEEP:BEEP:CLOSE #1
LONG IF MacBin=True
GOSUB "GetFileInfo":' read in the file info on this file
GOSUB "SetFileInfo": ' update According TO The MacBinary DATA
END IF
LONG IF MacName$="UNTITLED"
NewName$=FILES$(0,"SAVE File as WHAT?","UNTITLED",Vol1%)
IF NewName$<>"" THEN RENAME MacName$ TO NewName$,Vol%
END IF
FN Push (RECWIN):FN Push(CloseEvent)
END IF
LONG IF RX$=CHR$(Can):' see if remote aborted
FN Push (RECWIN):FN Push(CloseEvent):CLOSE #1
END IF
END IF
END SELECT
'
C=ASC(RX$):' get the character value to work on the CRC/Checksum on
'
SELECT Count:' find out what character in the block we are at
CASE 0:' see if it starts with a START OF HEADER byte
RecSoh=C:' get the Start of Header we received
'
CASE 1:' check the first byte against the BLOCK NUMBER
RecvBlock=C:' get the block number the remote is sending
'
CASE 2:' last, check the compliment of the block number
Compliment=BlockCount XOR 255:' generates the compliment of the block number
RecvComp=C:' get the compliment of the block number
'
CASE 131:' CRC LSB byte from remote (OR CHECKSUM VALUE)
ChkSum=C:' this is the checksum value we want to use
'
END SELECT
'
LONG IF Count>2 AND Count<131
GOSUB"Do_CheckSum":GOSUB "DO_CRC":' calculate based on data received
XELSE
IF Count>2 GOSUB "DO_CRC":' always do a CRC even if we dont need it
END IF
Count=Count+1
'
LONG IF Pbut(5)=1 AND Count=132:' if a 1 we are using CHECKSUM NOT CRC
IF CheckSum<>ChkSum THEN Retry=True:' if not correct then we got an error
Count=Count+1:' then bump up counter so we use same remaining routines
END IF
LONG IF Count=133:' see if we have got a full block count
'
IF RecSoh<>Soh THEN Retry=True:' if they sent anything other than SOH, retry
'
LONG IF RecvBlock>BlockCount:' if we are too far out, ABORT!
FN Push(RECWIN):FN Push(CloseEvent):' close receive window first
Abort=True:GOSUB "Clear_Line":' set flag and wait for pause in receiving
LONG IF RecBlock=1
RETURN
XELSE
CLOSE #1:KILL MacName$:RETURN
END IF
END IF
'
LONG IF RecvBlock<BlockCount:' usually means a duplicate block, kick them up 1
PRINT #SerPort,CHR$(Ack);:' so we get the block we really want
RETURN
END IF
'
IF RecvComp<>Compliment THEN Retry=True:' if check if block is wrong, flag
'
LONG IF Pbut(5)=2:' looking for CRC check digits
IF CRCHI OR CRCLO <>0 THEN Retry=True:' Will equal a LOGICAL 0 if CRC correct
END IF
'
SELECT Retry
CASE True
XResult=Nak
CASE False
XResult=Ack
END SELECT
'
LONG IF Retry=False:' if false, then we got a good block
LONG IF RecBlock=1:' do an automatic check for MacBinary II protocol
LONG IF ASC(MID$(RECV$,1,1))=0 AND ASC(MID$(RECV$,75,1))=0
GOSUB "INIT_CRC":' start by setting CRC to 0
FOR ChkChr=1 TO 124:' characters to check for CRC calcs
C=ASC(MID$(RECV$,ChkChr,1)):GOSUB "DO_CRC":' read byte, calculate
NEXT ChkChr:GOSUB "FIND_CRC":' calculate total CRC done in
MSBCRC=ASC(MID$(RECV$,125,1)):LSBCRC=ASC(MID$(RECV$,126,1))
IF LSBCRC<>CRCLO AND MSBCRC<>CRCHI THEN MacBin=False ELSE MacBin=True
LONG IF MacBin=False:' see if its the older MacBinary I protocol
IF ASC(MID$(RECV$,83,1))=0 THEN MacBin=True:' checks older protocol
END IF
END IF
LONG IF MacBin=True
GOSUB "Extract_Filename":' get out filename and show
GOSUB "Extract_FileInfo":' retrieve the creator/type and show it
GOSUB "Extract_Size":' get the DATA and RESOURCE sizes
GOSUB "Extract_FindrAtt":' get out the FINDER attribute flags
Protocol$="MacBinary II":GOSUB "Show_Protocol":GOSUB"Show_Graph"
GOSUB "Open_File":' go setup file for writing to
XELSE
GOSUB "Untitled_Filename":'untitled name and also
GOSUB "Show_Name":' show the name we are defaulting to
Protocol$="Unknown":GOSUB "Show_Protocol"
HasData=True:HasRes=False:GOSUB "Open_File":' open as a DATA file only
END IF
END IF
'
LONG IF MacBin=True AND RecBlock<>1
LONG IF Complete=False
TotalBytes&=TotalBytes&+128:Temp$=STR$(TotalBytes&)
RecvBytes&=RecvBytes&+128:' amount we have got thus far
GOSUB "Update_Size":' show bytes received in window
GOSUB "Move_Graph":' updates the slider in window
Block$=MID$(RECV$,1,128):BPtr&=VARPTR(Block$)+1:' point to data
LONG IF RecvBytes&<WriteSize&
BlkLen&=128
XELSE
BlkLen&=128-(RecvBytes&-WriteSize&):' get residual block size
Complete=True
END IF
LONG IF BlkLen&<>0:' check to see if on a 128 byte boundry
WRITE FILE #1,BPtr&,BlkLen&:' write 128 bytes of data
XELSE
Complete=True:' else we ended on a 128 byte border
END IF
END IF
IF Complete=True THEN GOSUB "Check_Resource":' see if using resource fork
XELSE
LONG IF MacBin=False
TotalBytes&=TotalBytes&+128:Temp$=STR$(TotalBytes&)
GOSUB "Update_Size":' show bytes received in window
Block$=MID$(RECV$,1,128):BlkLen&=128:BPtr&=VARPTR(Block$)+1:' point to data
WRITE FILE #1,BPtr&,BlkLen&
END IF
END IF
'
RecBlock=RecBlock+1:' increment for the next block# received
BlockCount=BlockCount+1:' then add to our counter for block numbers
'
IF BlockCount=256 THEN BlockCount=0
PRINT #SerPort,CHR$(XResult);:' send out either good or bad indicator
'
XELSE
Recv_Error=Recv_Error+1:GOSUB "Show_Error":' displays the error count
LONG IF Recv_Error=10
GOSUB "Clear_Line":' send out the cancel bytes first
FN Push (RECWIN):FN Push(CloseEvent)
LONG IF RecBlock>1:' see if still trying for the first block
CLOSE #1:KILL MacName$,Vol%
END IF
END IF
'
END IF
Count=0:Retry=False:GOSUB"INIT_CRC":GOSUB "INIT_CHECKSUM"
END IF
'
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' Xmodem Send Subroutines
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Wait_Start"
LONG IF LOF(SerPort):' wait for a value from the port
READ #SerPort,RX$;1:' read only if we got something
'
LONG IF RX$="C"
GOSUB "Check_MacBinary":' see if sending a Macbinary file
CRC=True:Xmit_Step=2:' they want CRC, so continue
GOSUB "Show_Send":' show we are sending now
RETURN
END IF
'
LONG IF RX$=CHR$(Nak)
GOSUB "Check_MacBinary":' see iuf we have to open the file or what
SUM=True:Xmit_Step=2:' else then want checksum
GOSUB "Show_Send":' show we are sending now
RETURN
END IF
'
IF RX$=CHR$(Can) THEN GOSUB "Cancel_Send":RETURN
END IF
RETURN
'--------------------------------------------------------------
"Send_Data"
Retry=False:' set this flag so we don't repeat routine if error
GOSUB "Send_Header":' send out SOH, block#, compliment Block#
GOSUB "Send_Block":' send out the 128 byte block of data
GOSUB "Send_Check":' send out either CRC or Checksum value
Xmit_Step=3:' advance to next step and wait for reply
RETURN
'--------------------------------------------------------------
"Send_Header"
Time_Out=0:' reset waiting time for reply from remote first
PRINT #SerPort,CHR$(Soh);:' send out start of header
PRINT #SerPort,CHR$(XmitBlock);:' send out block number this time
Compliment=XmitBlock XOR 255:' generates the compliment of the block number
PRINT #SerPort,CHR$(Compliment);:' send out compliment of block#
RETURN
'--------------------------------------------------------------
"Send_Block"
GOSUB "INIT_CRC":GOSUB "INIT_CHECKSUM":' set check bytes to 0
FOR ChkChr=1 TO 128:' characters to check for CRC calcs
C=ASC(MID$(RECV$,ChkChr,1))
PRINT #SerPort,CHR$(C);:' data byte out the port
GOSUB "Do_CheckSum":' go calculate the checksum
GOSUB "DO_CRC":' read byte, calculate
NEXT ChkChr
RETURN
'--------------------------------------------------------------
"Send_Check"
GOSUB "FIND_CRC":' calculate total CRC
'
LONG IF CRC=True:' if they wanted CRC send them that
PRINT #SerPort,CHR$(CRCHI);:' MSBCRC
PRINT #SerPort,CHR$(CRCLO);:' LSBCRC
XELSE
PRINT #SerPort,CHR$(CheckSum);:' else send them the checksum value
END IF
RETURN
'--------------------------------------------------------------
"Verify"
LONG IF LOF(SerPort):' wait for a value from the port
READ #SerPort,RX$;1:' read only if we got something
'
LONG IF RX$=CHR$(Ack)
LONG IF MacBin=True AND BlockCount>1:' if true, then do calcs
TotalBytes&=TotalBytes&+128:Temp$=STR$(TotalBytes&)
XmitBytes&=XmitBytes&+128:' add 128 to the total we have sent
GOSUB "Update_Size":' update amount sent on screen
GOSUB "Move_Graph":' and move the graph on screen too!
END IF
'
LONG IF MacBin=False:' else see if we are sending TEXT file
TotalBytes&=TotalBytes&+128:Temp$=STR$(TotalBytes&)
XmitBytes&=XmitBytes&+128:' add 128 to the total we have sent
GOSUB "Update_Size":' update amount sent on screen
GOSUB "Move_Graph":' and move the graph on screen too!
END IF
'
Xmit_Step=2:' set to send the next block
GOSUB "Read_Block":' go read in next block to send
XmitBlock=(XmitBlock+1)AND 255:' allows it to be 8 bit counter
BlockCount=BlockCount+1:' increment the total block counter
RETURN
END IF
'
LONG IF RX$=CHR$(Nak) OR RX$="C"
Retry=True:Xmit_Step=2:' else resend same block
Recv_Error=Recv_Error+1:GOSUB "Show_Error":' displays the error count
LONG IF Recv_Error=10
FN Push (SNDWIN):FN Push(CloseEvent)
Abort=True
END IF
RETURN
END IF
'
IF RX$=CHR$(Can) THEN GOSUB "Cancel_Send":RETURN
END IF
RETURN
'--------------------------------------------------------------
"Done"
LONG IF LOF(SerPort):' wait for data coming in
READ #SerPort,RX$;1:' read only if we got something
LONG IF RX$=CHR$(Ack)
PRINT #SerPort,CHR$(Eot);:' send back again
Xmit_Step=5:' move the last subroutine
END IF
END IF
RETURN
'--------------------------------------------------------------
"Wait_Ack"
LONG IF LOF(SerPort):' wait til data shows up
READ #SerPort,RX$;1:' read in the ACK (we just lose it)
FN Push (SNDWIN):FN Push(CloseEvent)
BEEP:BEEP:' we are done!
END IF
RETURN
'--------------------------------------------------------------
"Check_MacBinary"
LONG IF MacBin=True:' if Macbinary wanted don't load blocks
Protocol$="MacBinary II":' show we are sending a Macbinary file
GOSUB "Open_SendFile":' open the file we are going to send DONT READ DATA!
XELSE:' else we want to read in some data
GOSUB "Open_SendFile":' open the file, get the size to write to remote
GOSUB "Read_Block":' go read block, pad if needed
Protocol$="TEXT"
END IF
GOSUB "Show_Protocol":' show type of file we are sending TEXT or MACBINARY
GOSUB "Show_Graph":' and draw the percent scale on the dialog box
RETURN
'--------------------------------------------------------------
"Cancel_Send"
Abort=True:CLOSE #1
FN Push (SNDWIN):FN Push(CloseEvent)
RETURN
'--------------------------------------------------------------
"Read_Block"
BPtr&=VARPTR(RECV$)+1:' point to start of block data
'
LONG IF XmitBytes&+128 > WriteSize&:' check for small amount left
BlkLen&=WriteSize&-XmitBytes&:' gets the amount left to send this time
RECV$=STRING$(128,CHR$(65)):' pad whole block first
XmitBytes&=WriteSize&:' set for full size sent
XELSE
BlkLen&=128
END IF
'
LONG IF BlkLen&>0
READ FILE #1,BPtr&,BlkLen&:' read in remainder of bytes from file
XELSE
CLOSE #1:' close the file since this portion is done
LONG IF SecPass=False AND HasRes=True:' see if we completed data, need RES
OPEN "IR",1,MacName$,,Vol%: ' write only to the resource fork of the file
WriteSize&=ResFork&:' used for writing same size to disk
XmitBytes&=0:' set to zero for total sent out
SecPass=True:' so we don't reopen the resource file again
GOTO "Read_Block":' and repeat to start the next routine
XELSE
PRINT #SerPort,CHR$(Eot);:' if ended on 128 byte boundry, send out eot
Xmit_Step=4:' signal to routine we are done
END IF
END IF
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' CRC and Checksum Subroutines
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"INIT_CRC"
CRCHI=0:CRCLO=0:' set initial CRC value to nothing (zero)
RETURN
'--------------------------------------------------------------
"INIT_CHECKSUM"
CheckSum=0:' set to zero in case user wants to use checksum
RETURN
'--------------------------------------------------------------
"DO_CRC":' value to use is in variable C (a number)
H=CRCHI:L=CRCLO:' get old CRC value
FOR B=1 TO 8:' bit to shift positions for calculations
C=C<<1:' not pretty but we need to rotate the bits to find crc
LONG IF C>255
C=C AND 255:'we have a carry so rotate both H & L now
L=(L<<1)+1:' rotate in the carry from C
LONG IF L>255:' if L generated a carry, we also add 1 to H for rotate
L=L AND 255:' get back to limited value (minus 1 for rotate)
H=(H<<1)+1
LONG IF H>255
H=(H AND 255) XOR 16:L=L XOR 33
END IF
XELSE
H=H<<1:' else we just rotate the HIGH byte
LONG IF H>255
H=(H AND 255) XOR 16:L=L XOR 33
END IF
END IF
XELSE
L=L<<1:' else we do a rotate without the carry from C
LONG IF L>255:' if L generated a carry, we also add 1 to H for rotate
L=L AND 255:' get back to limited value
H=(H<<1)+1
LONG IF H>255
H=(H AND 255) XOR 16:L=L XOR 33
END IF
XELSE
H=H<<1
LONG IF H>255
H=(H AND 255) XOR 16:L=L XOR 33
END IF
END IF
END IF
NEXT B:CRCHI=H:CRCLO=L:RETURN
'--------------------------------------------------------------
"FIND_CRC":' does the last two bytes where the CRC actually goes
C=0:GOSUB "DO_CRC":C=0:GOSUB "DO_CRC":RETURN
'--------------------------------------------------------------
"Do_CheckSum"
CheckSum=CheckSum+C:' adds the value of the character received to what we got
IF CheckSum>255 THEN CheckSum=CheckSum AND 255:' turns it into an 8 bit counter
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' MacBinary II Decoding Subroutines
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Extract_Filename"
NameLen=ASC(MID$(RECV$,2,1)):' gets the length counter for the filename
MacName$=MID$(RECV$,3,NameLen):GOSUB"Show_Name":RETURN
'--------------------------------------------------------------
"Untitled_Filename"
FileType$="TEXT":MacName$="UNTITLED"
SELECT
CASE Pbut(1)=2
DEF OPEN="TEXTMSWD"
FileCreator$="MSWD"
CASE Pbut(2)=2
FileCreator$="MACA"
DEF OPEN="TEXTMACA"
CASE Pbut(3)=2
FileCreator$="nX^n"
DEF OPEN="TEXTnX^n"
CASE Pbut(4)=2
FileCreator$="????"
DEF OPEN="TEXT????"
END SELECT
GOSUB "Show_CreatorType":' show what we are getting on screen
RETURN
'--------------------------------------------------------------
"Extract_FileInfo"
FileType$=MID$(RECV$,66,4):FileCreator$=MID$(RECV$,70,4)
TempF$=FileType$+FileCreator$
DEF OPEN=TempF$
GOSUB"Show_CreatorType":RETURN
'--------------------------------------------------------------
"Extract_Size"
DataSize$=MID$(RECV$,84,4):ResSize$=MID$(RECV$,88,4)
DEFSTR LONG
DataFork&=CVI(DataSize$):ResFork&=CVI(ResSize$)
DEFSTR WORD
IF DataFork&<>0 THEN HasData=True ELSE HasData=False:' set flags
IF ResFork&<>0 THEN HasRes=True ELSE HasRes=False:' for both forks
TotalSize&=(((DataFork&+ResFork&)\128)+.5)*128
RETURN
'--------------------------------------------------------------
"Extract_FindrAtt"
FindrFlags%=ASC(MID$(RECV$,74,1)):' this is the FINDER attribute flags
FindrFlags%=FindrFlags% << 8:' shift over to the HIGH byte in word
'bits 0 thru 7 are obtained (high order byte wanted)
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' MacBinary II Encoding Subroutine
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Encode_MacBinary"
RECV$=STRING$(128,CHR$(0)):' zero out the whole first block in case
'
MID$(RECV$,2,1)=CHR$(LEN(MacName$)):' put in the filename length
MID$(RECV$,3,LEN(MacName$))=MacName$:' then stuff in the filename
'
DEFSTR LONG
DataSize$=MKI$(DataFork&):ResSize$=MKI$(ResFork&)
DEFSTR WORD
MID$(RECV$,84,4)=DataSize$:MID$(RECV$,88,4)=ResSize$:' puts in lengths
'
GOSUB "GetFileInfo":' go get the file information
DEFSTR LONG
Ctype&=PEEK LONG(Hparmblkptr&+36)
FileCreator$=MKI$(Ctype&)
Ftype&=PEEK LONG(Hparmblkptr&+32)
FileType$=MKI$(Ftype&)
DEFSTR WORD
'
MID$(RECV$,66,4)=FileType$:' insert the file type string
MID$(RECV$,70,4)=FileCreator$:' insert the file creator
'
OldFlags%=OldFlags%>>8:' shift the HIGH order bits down to low ones
MID$(RECV$,74,1)=CHR$(OldFlags%):' insert the finder info
'
MID$(RECV$,123,1)=CHR$(129):MID$(RECV$,124,1)=CHR$(129):' shows MacBinary II
'
LONG IF Pbut(7)=2:' check to see if MacBinary II in effect
MacBin=True:' if yes, then set flag true
Protocol$="MacBinary II"
FOR ChkChr=1 TO 124:' characters to check for CRC calcs
C=ASC(MID$(RECV$,ChkChr,1)):GOSUB "DO_CRC":' read byte, calculate
NEXT ChkChr:GOSUB "FIND_CRC":' calculate total CRC done in
MID$(RECV$,125,1)=CHR$(MSBCRC):' stuff in the CRC values for Macbinary II
MID$(RECV$,126,1)=CHR$(LSBCRC):' protocol detection (if wanted)
XELSE
MacBin=False:' else its not true, just a who knows type file
Protocol$="Who Knows..."
END IF
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' Send Xmodem File Subroutine
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Open_SendFile"
LONG IF HasData=True AND HasRes=False
OPEN "ID",1,MacName$,,Vol%:' set up file for writing to
WriteSize&=DataFork&:' used for writing same size to disk
RETURN
END IF
LONG IF HasData=False AND HasRes=True
OPEN "IR",1,MacName$,,Vol%: ' write only to the resource fork of the file
WriteSize&=ResFork&:' used for writing same size to disk
SecPass=True:' so we don't reopen the resource file again
RETURN
END IF
LONG IF HasData=True AND HasRes=True
OPEN"ID",1,MacName$,,Vol%:' just write to a data file first
WriteSize&=DataFork&:' used for writing same size to disk
END IF
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' Receive Xmodem File Subroutines
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Open_File"
GOSUB "GetVolNum":' gets the volume number in Vol%
LONG IF HasData=True AND HasRes=False
OPEN "OD",1,MacName$,,Vol%:' set up file for writing to
WriteSize&=DataFork&:' used for writing same size to disk
RETURN
END IF
LONG IF HasData=False AND HasRes=True
OPEN "OR",1,MacName$,,Vol%: ' write only to the resource fork of the file
WriteSize&=ResFork&:' used for writing same size to disk
SecPass=True:' so we don't reopen the resource file again
RETURN
END IF
LONG IF HasData=True AND HasRes=True
OPEN"OD",1,MacName$,,Vol%:' just write to a data file first
WriteSize&=DataFork&:' used for writing same size to disk
END IF
RETURN
'--------------------------------------------------------------
"Check_Resource"
LONG IF SecPass=False:' see if first time through
LONG IF HasRes=True
CLOSE #1:' close off the file first
OPEN "OR",1,MacName$,,Vol%: ' write only to the resource fork of the file
WriteSize&=ResFork&:' used for writing same size to disk
RecvBytes&=0:' set to zero for amount received for new fork
Complete=False:' then start routine again
SecPass=True:' only allowed this routine once
END IF
END IF
RETURN
'--------------------------------------------------------------
"GetVolNum"
X = FN GETVOL(VARPTR(PBlock$)):' gets the data into a string first
Vol%=PEEK WORD(VARPTR(PBlock$)+22):' extracts the current volume ref number
RETURN
'--------------------------------------------------------------
"Rename_File":' this is only used for ymodem type transfers
TEXT 0,12,,0:' set to Chicago 12
T = 25:L = 13:B = 41:R = 145
Temp$ = "Will rename file to :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
L = 148:R = 424
Temp$ = "new filename goes here"
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' Graphic Percentage Subroutine
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Move_Graph"
CALL GETPENSTATE(PenSpecs$):' Record the current pen state
T=211:L=26:B=236:R=415:' rect that we get to paint in
PEN ,1,1,8,3:' set for a grey scale drawing
SizePercent!=((TotalBytes&*100)\TotalSize&)
R=(((390*SizePercent!)-.5)\100)+L:IF R>415 THEN R=415
CALL PAINTRECT(T)
CALL SETPENSTATE(PenSpecs$):' Restore the current pen state
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' Send/Receive Dialog Info Display Subroutines
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Show_Name"
TEXT 0,12,,0:' set to Chicago 12
T=8:L = 148:B=24:R = 381
Temp$ = MacName$
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
RETURN
'--------------------------------------------------------------
"Show_Protocol"
TEXT 0,12,,0:' set to Chicago 12
T=64:L = 149:B=80:R = 264
Temp$ = Protocol$
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
RETURN
'--------------------------------------------------------------
"Show_CreatorType"
TEXT 0,12,,0:' set to Chicago 12
T=151:L = 149:B=167:R = 195
Temp$ = FileCreator$
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 131:L = 150:B = 147:R = 195
Temp$ = FileType$
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
RETURN
'--------------------------------------------------------------
"Show_Error"
TEXT 0,12,,0:' set font to Chicago first
T=84:L = 149:B=100:R = 183
Temp$ = STR$(Recv_Error)
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
RETURN
'--------------------------------------------------------------
"Update_Size"
'Shows the number of bytes received thus far
TEXT 0,12,,0:' set to Chicago 12
T=44:L=147:B=60:R=319
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0):RETURN
'--------------------------------------------------------------
"Show_Status"
Temp$ = "Receiving Data":GOSUB "Show_Msg":RETURN
'--------------------------------------------------------------
"Show_Send"
Temp$="Sending Data"
"Show_Msg"
TEXT 0,12,,0:' set to Chicago 12
T = 111:L = 150:B = 127:R = 282
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
RETURN
'--------------------------------------------------------------
"Show_Graph"
CALL GETPENSTATE(PenSpecs$):' Record the current pen state
T = 210:L = 25:B = 237:R = 416
PEN ,1,1,8,19
CALL PAINTRECT(T)
PEN ,,1,8,0
CALL FRAMERECT(T)
T = 187:L = 153:B = 203:R = 309
Temp$ = "Progress Indicator %"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
TEXT 4,9,,0
T=240:L = 23:B=251:R = 32
Temp$ = "0"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
L=58:R=72
Temp$ = "10"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
L = 97:R = 109
Temp$ = "20"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
L = 136:R = 150
Temp$ = "30"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
L = 174:R = 189
Temp$ = "40"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
L = 214:R = 228
Temp$ = "50"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
L = 253:R = 268
Temp$ = "60"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
L = 292:R = 308
Temp$ = "70"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
L = 332:R = 345
Temp$ = "80"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
L = 370:R = 386
Temp$ = "90"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
L = 407:R = 427
Temp$ = "100"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
CALL SETPENSTATE(PenSpecs$):' Restore the current pen state
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' Receive Abort Subroutine
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Clear_Line":' loop til sender stops first
IF LOF(SerPort) THEN READ #SerPort,RX$;1:GOTO "Clear_Line"
FOR T=1 TO 5:PRINT #SerPort,CHR$(Can);:NEXT T:' send out the cancel bytes
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' Receive Initial Start Subroutine
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
'--------------------------------------------------------------
"Check_Receive"
SELECT Recv_Step
CASE 1
LONG IF Pbut(5)=2:' see if CRC wanted
PRINT #SerPort,"C";:' send out a C to start this mess
XELSE
PRINT #SerPort,CHR$(Nak):' else we want checksum
END IF
Time_Out=Time_Out+1
LONG IF Time_Out=60
GOSUB "Clear_Line":' send out cancel bytes too
FN Push (RECWIN):FN Push(CloseEvent)
BEEP:BEEP:' let them know we timed out
END IF
END SELECT
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' Options Menu Dialog Subroutines
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Update Text"
FOR T=1 TO 4:IF Pbut(T)=1 THEN NEXT T
Pbut(T)=1:BUTTON T,Pbut(T)
Pbut(Ref)=2:BUTTON Ref,Pbut(Ref)
RETURN
'--------------------------------------------------------------
"Update TransType"
LONG IF Ref=5
Pbut(5)=2:Pbut(6)=1
XELSE
Pbut(5)=1:Pbut(6)=2
END IF
BUTTON 5, Pbut(5)
BUTTON 6, Pbut(6)
RETURN
'--------------------------------------------------------------
"Update MacBin"
IF Pbut(7)=2 THEN Pbut(7)=1 ELSE Pbut(7)=2
BUTTON 7, Pbut(7)
RETURN
'--------------------------------------------------------------
"Close TranSet"
FN Push(PROSET)
FN Push(CloseEvent)
RETURN
'---------------------------------------------------------------
"CanTranSet"
FOR T=1 TO 7:Pbut(T)=Hold(T):NEXT T:' Return all values to originals
GOSUB "Close TranSet":RETURN
'--------------------------------------------------------------
"FNT9"
Tbut(1)=2:Tbut(2)=1:GFSize=9:GOSUB "Update Font":RETURN
"FNT12"
Tbut(1)=1:Tbut(2)=2:GFSize=12:GOSUB "Update Font":RETURN
"BLK"
Tbut(3)=2:Tbut(4)=1:Cur$=" ":TMode=5:GOSUB "Update Cursor":RETURN
"UL"
Tbut(3)=1:Tbut(4)=2:Cur$="_":TMode=1:GOSUB "Update Cursor":RETURN
"BCK"
Tbut(5)=2:Tbut(6)=1:GOSUB "Update Key":RETURN
"DEL"
Tbut(5)=1:Tbut(6)=2:GOSUB "Update Key":RETURN
"LOC"
Tbut(7)=Tbut(7) XOR 1:GOSUB "Update Loc":RETURN
"REM"
Tbut(8)=Tbut(8) XOR 1:GOSUB "Update Rem":RETURN
"LF"
Tbut(9)=Tbut(9) XOR 1:GOSUB "Update LF":RETURN
'---------------------------------------------------------------
"Update Font"
BUTTON 1, Tbut(1)
BUTTON 2, Tbut(2)
RETURN
'---------------------------------------------------------------
"Update Cursor"
BUTTON 3, Tbut(3)
BUTTON 4, Tbut(4)
RETURN
'---------------------------------------------------------------
"Update Key"
BUTTON 5, Tbut(5)
BUTTON 6, Tbut(6)
RETURN
'---------------------------------------------------------------
"Update Loc"
BUTTON 7, Tbut(7)+1
RETURN
'---------------------------------------------------------------
"Update Rem"
BUTTON 8, Tbut(8)+1
RETURN
'---------------------------------------------------------------
"Update LF"
BUTTON 9, Tbut(9)+1
RETURN
'---------------------------------------------------------------
"Close Tset"
FN Push(TSWIN)
FN Push(CloseEvent)
RETURN
'---------------------------------------------------------------
"CanTset"
FOR T=1 TO 10:Tbut(T)=Hold(T):NEXT T:' Return all values to originals
GOSUB "Close Tset":RETURN
'---------------------------------------------------------------
"Toggle Blink"
LONG IF Tbut(10)=2
Tbut(10)=1:EnBlink=0
XELSE
Tbut(10)=2:EnBlink=1
END IF
BUTTON 12, Tbut(10)
RETURN
'---------------------------------------------------------------
"Change Baud"
FOR OldBaud=1 TO 7:IF Cbut(OldBaud)<>2 THEN NEXT OldBaud:RETURN:' Has to be found
Cbut(OldBaud)=1
ON OldBaud GOSUB "C1","C2","C3","C4","C5","C6","C7"
Cbut(Ref)=2:ON Ref GOSUB "C1","C2","C3","C4","C5","C6","C7"
GOSUB "UART"
RETURN
'---------------------------------------------------------------
"Change WordLength"
Cbut(Ref)=2:IF Ref=8 THEN Cbut(9)=1 ELSE Cbut(8)=1
WordLen=Ref-8:' equals either a 0 for 7 bit or 1 for 8 bit
GOSUB "Update WordLen":GOSUB "UART":RETURN
'---------------------------------------------------------------
"Change StopBits"
Cbut(Ref)=2:IF Ref=10 THEN Cbut(11)=1 ELSE Cbut(10)=1
StopBit=Ref-10:' 0=1 stop, 1=2 stop bits
GOSUB "Update Stopbits":GOSUB "UART":RETURN
'---------------------------------------------------------------
"Change Parity"
FOR OldParity=12 TO 14:IF Cbut(OldParity)<>2 THEN NEXT OldParity:RETURN:' Must be found
Cbut(OldParity)=1
ON OldParity-11 GOSUB "P1","P2","P3"
Cbut(Ref)=2:ON Ref-11 GOSUB "P1","P2","P3"
GOSUB"UART":RETURN
'---------------------------------------------------------------
"Change Port"
Cbut(Ref)=2
LONG IF Ref=15
Cbut(16)=1:SerPort=-1:' set for modem port
XELSE
Cbut(15)=1:SerPort=-2:' set for printer port
END IF
GOSUB "Update Port":GOSUB "UART":RETURN
'---------------------------------------------------------------
"C1"
BUTTON 1, Cbut(1):Baud=300:RETURN
"C2"
BUTTON 2, Cbut(2):Baud=1200:RETURN
"C3"
BUTTON 3, Cbut(3):Baud=2400:RETURN
"C4"
BUTTON 4, Cbut(4):Baud=4800:RETURN
"C5"
BUTTON 5, Cbut(5):Baud=7200:RETURN
"C6"
BUTTON 6, Cbut(6):Baud=9600:RETURN
"C7"
BUTTON 7, Cbut(7):Baud=19200:RETURN
'---------------------------------------------------------------
"Update WordLen"
BUTTON 8, Cbut(8)
BUTTON 9, Cbut(9)
RETURN
'---------------------------------------------------------------
"Update Stopbits"
BUTTON 10, Cbut(10)
BUTTON 11, Cbut(11)
RETURN
'---------------------------------------------------------------
"P1"
BUTTON 12, Cbut(12)
Parity=0:RETURN
"P2"
BUTTON 13, Cbut(13)
Parity=2:RETURN
"P3"
BUTTON 14, Cbut(14)
Parity=1:RETURN
'---------------------------------------------------------------
"Update Port"
BUTTON 15, Cbut(15)
BUTTON 16, Cbut(16)
RETURN
'---------------------------------------------------------------
"Close Cset"
FN Push(CSWIN)
FN Push(CloseEvent)
RETURN
'---------------------------------------------------------------
"Close About"
FN Push(ABTWIN)
FN Push(CloseEvent)
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' FINDER INFO Subroutines
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"GetFileInfo"
'
Hparmblkptr&=VARPTR(Paramblock$)
'
Iocompletion&=0:POKE LONG Hparmblkptr&+12,Iocompletion&
'
Ionameptr&=VARPTR(MacName$)
POKE LONG Hparmblkptr&+18,Ionameptr&
'
Iovrefnum%=Vol%:POKE WORD Hparmblkptr&+22,Iovrefnum%
'
POKE WORD Hparmblkptr&+28,0
POKE WORD Hparmblkptr&+48,0
'
Oserr=FN GETFILEINFO(Hparmblkptr&)
'
Ioresult%=PEEK WORD(Hparmblkptr&+16)
IF Ioresult%<>0 THEN BEEP:RETURN:' back if it was an error read
'
OldFlags%=PEEK WORD(Hparmblkptr&+40):' finder attribute flags (HI/LO byte)
RETURN
'---------------------------------------------------------------
"SetFileInfo"
POKE WORD(Hparmblkptr&+40),FindrFlags%:' update the finder flags
'
Oserr=FN SETFILEINFO(Hparmblkptr&)
'
Ioresult%=PEEK WORD(Hparmblkptr&+16)
IF Ioresult%<>0 THEN BEEP:RETURN:' back if it was an error write
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' • UART CONTROL •
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"UART"
OPEN "C",SerPort,Baud,Parity,StopBit,WordLen,BufLen
HANDSHAKE SerPort,0:' set for no handshaking
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' • HANDLE RECVD CHARACTERS •
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"RECV1"
LONG IF ASC(RX$)>128
CV=ASC(RX$):CV=CV AND 127:RX$=CHR$(CV):' simply stripes HIGH bit
END IF
'
IF ASC(RX$)=0 THEN RETURN:' dont allow NULLS to come through
'
LONG IF ASC(RX$)<32:' test to see if we are getting a control code
CV=ASC(RX$):' get the current control value
RX$=MID$(Control$,CV,1):' get allowable control codes from string
IF ASC(RX$)=0 THEN RETURN:' dont allow codes we haven't defined
END IF
'
IF ASC(RX$)=127 THEN RX$=CHR$(8):' change DELETE to backspace
'
LONG IF WINDOW(0)=COMWIN AND CapFlag=1
PRINT #2,RX$;:' routine to write capture text to file
END IF
'
IF Tbut(8) THEN PRINT #SerPort,RX$;
"RECV"
LONG IF RX$=CHR$(8)
X=POS(0):GOSUB "OFF":IF ChrCnt=0 THEN GOSUB "ON":RETURN
ChrCnt=ChrCnt-1
SELECT ChrCnt
CASE 0
Screen$(Y)="":' empty string on full backspace
CASE >0
Screen$(Y)=LEFT$(Screen$(Y),ChrCnt)
END SELECT
GOTO "BACKSPACE"
END IF
'
LONG IF RX$=CHR$(7)
BEEP:GOSUB "ON":RETURN
END IF
'
LONG IF RX$=CHR$(10)
GOSUB "ON":RETURN
END IF
'
X=POS(0):GOSUB "OFF":PRINT RX$;:ChrCnt=ChrCnt+1
LONG IF RX$=CHR$(13)
IF ChrCnt=1 THEN Screen$(Y)=""
Y=Y+1:ChrCnt=0
XELSE
Screen$(Y)=Screen$(Y)+RX$: ' adds the printed character to the buffer
END IF
'
IF ChrCnt=CntMax THEN RX$=CHR$(13):GOTO "RECV":'do an autolinefeed
LONG IF Y>TSLines
Y=TSLines
FOR T=1 TO TSLines-1:SWAP Screen$(T),Screen$(T+1):NEXT T
Screen$(TSLines)=""
END IF
'
GOSUB "ON":' turn on cursor again
RETURN
'------------------------------------------------------------
"BACKSPACE"
X=POS(0):LOCATE X-1,Y
TEXT GFFont,GFSize,GFFace,7:PRINT " ";:LOCATE X-1,Y
TEXT GFFont,GFSize,GFFace,1:GOSUB "ON":RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
' • CONTROL THE CURSOR •
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"ON"
IF Wink=1 THEN RETURN:' back if already on
X=POS(0):LOCATE X,Y
"ON1"
TEXT GFFont,GFSize,GFFace,TMode:PRINT Cur$;
LOCATE X,Y:Wink=1
RETURN
'------------------------------------------------------------
"OFF"
IF Wink=0 THEN RETURN:' back if already off
LOCATE X,Y
TEXT GFFont,GFSize,GFFace,7:PRINT " ";
LOCATE X,Y
TEXT GFFont,GFSize,GFFace,1:Wink=0
RETURN
'------------------------------------------------------------
"Blink"
IF WINDOW(0)=RECWIN THEN GOSUB "Check_Receive":' if receiving
'
IF SendFlag=1 THEN RETURN:' back if sending text to remote
'
LONG IF WINDOW(0)=COMWIN AND EnBlink=1
SELECT Wink
CASE 0
GOSUB "ON":' turn on cursor
CASE 1
GOSUB "OFF":' turn off cursor
END SELECT
END IF
RETURN
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Menu"
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
MenuID=MENU(0):ItemID=MENU(1)
'---------------------------------------------------------------
LONG IF MenuID = 255:' Apple menu
FN Push (ABTWIN):' about window
FN Push (OpenEvent):' and open it
RETURN
END IF
'---------------------------------------------------------------
ON MenuID-127 GOSUB "File","Settings","Transfers"
CALL HILITEMENU(MenuUsed&):RETURN
'---------------------------------------------------------------
"File"
MenuUsed&=FileMenu&
ON ItemID GOTO "Open Settings","Save Settings","ClearScrn","X","Quit"
'---------------------------------------------------------------
"Settings"
MenuUsed&=SetMenu&
ON ItemID GOTO "TermSet","ComSet","TranSet"
'---------------------------------------------------------------
"Transfers"
MenuUsed&=ProMenu&
ON ItemID GOTO "SendASCII","Capture Text","XSend","XRecv"
'---------------------------------------------------------------
"Capture Text"
ProHndl&=FN GETMHANDLE(130):' get a pointer to the menu handle
SELECT CapFlag
CASE 0
CALL SETITEM(ProHndl&,2,"Stop Capture...")
F$=FILES$(0,"Save Configuration as...","Log File",Vol%)
LONG IF F$<>""
SELECT
CASE Pbut(1)=2
DEF OPEN="TEXTMSWD"
CASE Pbut(2)=2
DEF OPEN="TEXTMACA"
CASE Pbut(3)=2
DEF OPEN="TEXTnX^n"
CASE Pbut(4)=2
DEF OPEN="TEXTFAST"
END SELECT
OPEN "O",2,F$,,Vol%:' set up file for writing to
DEF OPEN="TEXTBTRM"
CapFlag=1:' turn on flag to tell us whats happening
END IF
CASE 1
CALL SETITEM(ProHndl&,2,"Capture Text...")
CLOSE #2:CapFlag=0
END SELECT
RETURN
'---------------------------------------------------------------
"SendASCII"
ProHndl&=FN GETMHANDLE(130)
SELECT SendFlag
CASE 0
CALL SETITEM(ProHndl&,1,"Stop Send...")
F$=FILES$(1,"TEXT",,Vol%)
LONG IF F$<>""
OPEN "I",3,F$,,Vol%
SendFlag=1:More=1
END IF
CASE 1
CALL SETITEM(ProHndl&,1,"Send Text...")
CLOSE #3:SendFlag=0
END SELECT
RETURN
'---------------------------------------------------------------
"XSend"
MacName$=FILES$(1,"",,Vol%):' ask for the filename to send
IF MacName$="" THEN RETURN
'
OPEN "ID",1,MacName$,,Vol%:' open the file to send
DataFork&=LOF(1,1):' read the length of the fork
CLOSE #1:' then close the file
'
OPEN "IR",1,MacName$,,Vol%:' open the resource fork of the file
ResFork&=LOF(1,1):' read in the size of the resource fork
CLOSE #1:' then close the file again
'
IF DataFork&<>0 THEN HasData=True ELSE HasData=False:' set flags
IF ResFork&<>0 THEN HasRes=True ELSE HasRes=False:' for both forks
TotalSize&=(((DataFork&+ResFork&)\128)+.5)*128:' used for graphing the send
'
GOSUB "Encode_MacBinary":' do this as a default
'
FN Push(SNDWIN):FN Push(OpenEvent):' open up the new window
'
CRC=False:' turn off sending CRC protocol
SUM=False:' turn off checksum protocol
Xmit_Step=1:' tells routine where in procedure we are
Time_Out=0:' sets the time out to zero for routine start
Recv_Error=0:' set total errors to 0
TotalBytes&=0:' set amount sent to null
XmitBytes&=0:' set amount sent per fork to zero
Count=0:' used for reading data from the disk file
Abort=False:' used in event trapping to cancel routine
Retry=False:' bad block flag
XmitBlock=1:' block number counter (8 bits only)
BlockCount=1:' used for a total block count
SecPass=False:' flag so we don't reopen after all is sent
CurStep=0:' value used for spinning beach ball
RETURN
'--------------------------------------------------------------
"XRecv"
FN Push (RECWIN)
FN Push (OpenEvent):' opens up my window (receive window)
Recv_Step=1:' set for start of receiving routine to start
Time_Out=0:' set the time out value for the initial start
Recv_Error=0:' set for no errors during receive
TotalBytes&=0:' set amount received to null
RecvBytes&=0:' set amount for each fork to zilch too!
Count=0
Abort=False:' used for user cancelled receiving
Retry=False
RecBlock=1
BlockCount=1
MacBin=False
Complete=False:'used for MacBinary to stop writing on full length
SecPass=False:' for both fork writing
CurStep=0:' setup for the spinning cursor beachball
RETURN
'--------------------------------------------------------------
"TranSet"
FN Push (PROSET)
FN Push (OpenEvent)
FOR T=1 TO 7:Hold(T)=Pbut(T):NEXT T:' get temp stuff
RETURN
'---------------------------------------------------------------
"Open Settings"
GOSUB "Load Uart":RETURN
'---------------------------------------------------------------
"Save Settings"
GOSUB "Save Uart":RETURN
'---------------------------------------------------------------
"ClearScrn"
FN Push (COMWIN):' then reopen it
FN Push (OpenEvent):
FN Push (COMWIN):' Close the Communications window first
FN Push (CloseEvent):' close my window first
RETURN
'---------------------------------------------------------------
"Quit" GOTO "Break"
'---------------------------------------------------------------
"TermSet"
FN Push(TSWIN):' Push first window on to stack
FN Push(OpenEvent):' Tell my event manager to open the window
FOR T=1 TO 10
Hold(T)=Tbut(T)
NEXT T:' Get current terminal values
RETURN
'---------------------------------------------------------------
"ComSet"
FOR T=1 TO 16
Hold(T)=Cbut(T)
NEXT T:' Get current communication values
FN Push(CSWIN):' Push first window on to stack
FN Push(OpenEvent):' Tell my event manager to open the window
RETURN
'---------------------------------------------------------------
"X" RETURN
'---------------------------------------------------------------
"Save Uart"
DEF OPEN="CNFGBTRM"
F$=FILES$(0,"Save Configuration as...","Default Settings",Vol%)
IF F$="" THEN RETURN:' back if CANCEL was selected
CURSOR=Watch:' show the watch cursor
OPEN "O",1,F$,,Vol%
"Save_Config"
FOR T=1 TO 10
WRITE #1,Tbut(T)
NEXT T:' writes out the terminal settings
FOR T=1 TO 16
WRITE #1,Cbut(T)
NEXT T:' writes out the UART settings
FOR T=1 TO 7
WRITE #1,Pbut(T)
NEXT T:' writes out the transfer settings
Cur=ASC(Cur$):' get the cursor currently being used
WRITE #1,GFSize,Cur,TMode:' writes out the current font size
WRITE #1,SerPort,Baud,Parity,StopBit,WordLen
CLOSE #1:' then close the file
CURSOR=Arrow:' return to the arrow cursor
RETURN
'---------------------------------------------------------------
"Load Uart"
DEF OPEN="CNFGBTRM"
F$=FILES$(1,"CNFG",,Vol%)
IF F$="" THEN RETURN:' back if cancel selected
"Read_Config"
LONG IF Flag=1
OPEN "I",1,"Default Settings":' uses a default name
IF ERROR GOSUB "No_Default":RETURN
XELSE
OPEN "I",1,F$,,Vol%
END IF
CURSOR=Watch:' enable the watch cursor
FOR T=1 TO 10
READ #1,Tbut(T)
NEXT T:' reads in the terminal settings
FOR T=1 TO 16
READ #1,Cbut(T)
NEXT T:' reads in the UART settings
FOR T=1 TO 7
READ #1,Pbut(T)
NEXT T:' reads in the transfer settings
READ #1,GFSize,Cur,TMode:' reads in the current font size
Cur$=CHR$(Cur):' get the cursor
READ #1,SerPort,Baud,Parity,StopBit,WordLen
CLOSE #1:' then close the file
GOSUB "UART":' reconfigure the UART settings
CURSOR=Arrow:' then change cursor back to an arrow
IF Flag=1 THEN Flag=0:RETURN:' don't open the windows if loading directly
FN Push (COMWIN):' set up events to close and open window for new
FN Push (OpenEvent):' settings to take effect
FN Push (COMWIN)
FN Push (CloseEvent)
RETURN
'---------------------------------------------------------------
"No_Default"
CURSOR=Watch:' change the cursor first
OPEN"O",1,"Default Settings":' filename to create
GOSUB"Save_Config":' write out the info to disk file
RETURN:' then back to routines
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
"Break"
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
'
'
IF WINDOW(0) THEN FN Push(BreakEvent):RETURN
'
CALL RELEASERESOURCE(FileMenu&):' we release menu resources
CALL RELEASERESOURCE(SetMenu&)
CALL RELEASERESOURCE(ProMenu&)
'
IF ResRef<>0 THEN CALL CLOSERESFILE(ResRef)
IF CapFlag=1 THEN CLOSE #2:' make sure file is closed
IF SendFlag=1 THEN CLOSE #3:' turn off all file sending
'
END
'
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
SEGMENT:' start to split things up here
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
'
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
'Window Routines
'›››œœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœœ›››
'”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’’
'““‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘
"Build"
'”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’’
'““‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘
Wnd2Build = FN Pop:' Pop window # from stack
SELECT Wnd2Build
CASE COMWIN
WINDOW Wnd2Build,"BasicTerm",(ScrnL+10,ScrnT+45)-(ScrnR-10,ScrnB-8),5
FN GetFht(GFFont,GFSize,GFFace,GFMode)
TSLines=(((ScrnB-10)-(ScrnT+45))/(FAsc+FDes+FLead))-1
FOR T=0 TO TSLines:Screen$(T)="":NEXT T:' clear out array on open
CLS:Y=0:X=0:LOCATE X,Y:ChrCnt=0:GOSUB "ON":CURSOR=Arrow
'
CASE TSWIN
T = 0:L = 0:B = 246:R = 397:Refresh=0:' Set TLBR to window size
' Offset the rect to the center of the screen
CALL OFFSETRECT(T,ScrnR/2-R/2,(ScrnB/2+8)-B/2)
WINDOW Wnd2Build,"TRMWIN",(L,T)-(R,B),-2
BUTTON 1, Tbut(1),"9",( 149, 44)-( 187, 60),3
BUTTON 2, Tbut(2),"12",( 271, 44)-( 314, 60),3
BUTTON 3, Tbut(3),"Block",( 149, 75)-( 209, 91),3
BUTTON 4, Tbut(4),"Underline",( 217, 74)-( 304, 90),3
BUTTON 5, Tbut(5),"Backspace",( 149, 106)-( 240, 122),3
BUTTON 6, Tbut(6),"Delete",( 271, 106)-( 339, 122),3
BUTTON 7, Tbut(7)+1,"Local",( 149, 137)-( 208, 153),2
BUTTON 8, Tbut(8)+1,"Remote",( 271, 137)-( 343, 153),2
BUTTON 9, Tbut(9)+1,"Add Linefeeds",(149,168)-(262,184),2
BUTTON 10, 1,"OK",( 291, 214)-( 385, 234),1
BUTTON 11,1,"Cancel",( 15, 215)-( 106, 235),1
BUTTON 12, Tbut(10),"Blinking",( 315, 74)-( 391, 90),3
'
CASE CSWIN
T = 0:L = 0:B = 247:R = 406:Refresh=0:' Set TLBR to window size
' Offset the rect to the center of the screen
CALL OFFSETRECT(T,ScrnR/2-R/2,(ScrnB/2+8)-B/2)
WINDOW Wnd2Build,"SETWIN",(L,T)-(R,B),-2
BUTTON 1, Cbut(1),"300",( 136, 31)-( 185, 47),3
BUTTON 2, Cbut(2),"1200",( 136, 55)-( 191, 71),3
BUTTON 3, Cbut(3),"2400",( 136, 79)-( 198, 95),3
BUTTON 4, Cbut(4),"4800",( 226, 31)-( 283, 47),3
BUTTON 5, Cbut(5),"7200",( 226, 56)-( 277, 72),3
BUTTON 6, Cbut(6),"9600",( 226, 79)-( 285, 95),3
BUTTON 7, Cbut(7),"19,200",( 315, 31)-( 385, 47),3
BUTTON 8, Cbut(8),"7",( 132, 108)-( 196, 124),3
BUTTON 9, Cbut(9),"8",( 227, 107)-( 290, 123),3
BUTTON 10, Cbut(10),"1",( 132, 140)-( 187, 156),3
BUTTON 11, Cbut(11),"2",( 227, 139)-( 291, 155),3
BUTTON 12, Cbut(12),"None",( 132, 171)-( 193, 187),3
BUTTON 13, Cbut(13),"Even",( 227, 170)-( 282, 186),3
BUTTON 14, Cbut(14),"Odd",( 315, 170)-( 363, 186),3
BUTTON 15, Cbut(15),"Modem",( 132, 205)-( 202, 221),3
BUTTON 16, Cbut(16),"Printer",( 227, 206)-( 295, 222),3
BUTTON 17, 1,"OK",( 341, 223)-( 396, 243),1
BUTTON 18, 1,"Cancel",( 9, 223)-( 68, 243),1
'
CASE SNDWIN
T = 0:L = 0:B = 261:R = 442:' Set TLBR to window size
BLOCKMOVE VARPTR(T),VARPTR(Mt),8:' shovel to my checking
' Offset the rect to the center of the screen
CALL OFFSETRECT(T,ScrnR/2-R/2,(ScrnB/2+8)-B/2)
WINDOW Wnd2Build,"Xmodem Send",(L,T)-(R,B),-5
'
CASE RECWIN
T = 0:L = 0:B = 261:R = 442:' Set TLBR to window size
BLOCKMOVE VARPTR(T),VARPTR(Mt),8:' shovel to my checking
' Offset the rect to the center of the screen
CALL OFFSETRECT(T,ScrnR/2-R/2,(ScrnB/2+8)-B/2)
WINDOW Wnd2Build,"Xmodem Receive",(L,T)-(R,B),-5
'
CASE PROSET
T = 0:L = 0:B = 155:R = 377:Refresh=0:' Set TLBR to window size
' Offset the rect to the center of the screen
CALL OFFSETRECT(T,ScrnR/2-R/2,(ScrnB/2+8)-B/2)
WINDOW Wnd2Build,"ProSet",(L,T)-(R,B),-2
BUTTON 1, Pbut(1),"MSWord 4",( 4, 55)-( 89, 71),3
BUTTON 2, Pbut(2),"MacWrite",( 108, 55)-( 195, 71),3
BUTTON 3, Pbut(3),"WriteNow!",( 212, 55)-( 310, 71),3
BUTTON 4, Pbut(4),"TEXT",( 316, 55)-( 370, 71),3
BUTTON 5, Pbut(5),"CRC",( 5, 103)-( 57, 119),3
BUTTON 6, Pbut(6),"Checksum",( 121, 104)-( 218, 120),3
BUTTON 7, Pbut(7),"MacBinary",( 277, 104)-( 373, 120),2
BUTTON 8, 1,"OK",( 300, 129)-( 362, 149),1
BUTTON 9, 1,"Cancel",( 9, 133)-( 65, 153),1
'
CASE ABTWIN
T = 0:L = 0:B = 255:R = 424:' Set TLBR to window size
' Offset the rect to the center of the screen
CALL OFFSETRECT(T,ScrnR/2-R/2,(ScrnB/2+8)-B/2)
WINDOW Wnd2Build,"ABOUTWIN",(L,T)-(R,B),-4
BUTTON 1, 1,"OK",( 344, 224)-( 410, 244),1
END SELECT
'
' Add window color table to window
'
LONG IF FN CheckColor
X = FN GETAUXWIN(WINDOW(14),Hndl&)
H& = FN GETRESOURCE(CVI("wctb"),1000+WINDOW(0))
LONG IF NOT FN RESERROR
Hndl& = FN NEWHANDLE(48)
LONG IF Hndl&
BLOCKMOVE PEEK LONG(H&),PEEK LONG(Hndl&),48
CALL RELEASERESOURCE(H&)
CALL SETWINCOLOR(WINDOW(14),Hndl&)
WINDOW Wnd2Build:WINDOW OUTPUT Wnd2Build
END IF
END IF
END IF
'
RETURN
'”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’’
'““‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘
"Format Wnd"
'”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’’
'““‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘
'
ColorOn = FN CheckColor:' Is color turned on?
'
LONG IF ColorOn
CALL GETFORECOLOR(RFore):' Record current foreground color
CALL GETBACKCOLOR(RBack):' Record current background color
END IF
'
CALL GETPENSTATE(PenSpecs$):' Record the current pen state
'
' Record the current font specs
TxFont=PEEK WORD(WINDOW(14)+68)
TxFace=PEEK WORD(WINDOW(14)+70)
TxMode=PEEK WORD(WINDOW(14)+72)
TxSize=PEEK WORD(WINDOW(14)+74)
'
'
LONG IF WINDOW(1) = COMWIN
TEXT GFFont,GFSize,GFFace,1
LONG IF ChrCnt<>0 OR Y<>0
CLS:' Clear the video display to redraw the window
LOCATE 0,0:' have to make sure of start position
SL=0:' Starting Line
IF Y=0 THEN GOTO "SkipLines"
"ReDisp"
PRINT Screen$(SL)
SL=SL+1:IF SL<>Y THEN GOTO "ReDisp"
"SkipLines"
FOR T=1 TO LEN(Screen$(SL)):PRINT MID$(Screen$(SL),T,1);:NEXT T
X=POS(0):Y=SL:LOCATE X,Y
GOSUB "ON1":' restore cursor location and turn it back on
XELSE
GOSUB "ON"
END IF
END IF
'
LONG IF WINDOW(1) = TSWIN AND Refresh=0
T = 11:L = 14:B = 27:R = 212
LONG IF ColorOn
Red = 0:Green = 0:Blue = 0
CALL RGBFORECOLOR(Red)
Red =-1:Green =-1:Blue =-1
CALL RGBBACKCOLOR(Red)
END IF
TEXT 0,12,0,0
Temp$ = "Terminal Settings :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 42:B = 200:R = 128
Temp$ = "Font Size :"+Cr$+""+Cr$+"Cursor Shape :"+Cr$+""+Cr$+"Backspace Key :"+Cr$+""+Cr$+"Echo :"+Cr$+""+Cr$+"LineFeeds : "
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
Refresh=1:' don't update this window anymore
END IF:' End of TSWIN format
'
'
LONG IF WINDOW(1) = CSWIN AND Refresh=0
T = 7:L = 5:B = 23:R = 180
LONG IF ColorOn
Red = 0:Green = 0:Blue = 0
CALL RGBFORECOLOR(Red)
Red =-1:Green =-1:Blue =-1
CALL RGBBACKCOLOR(Red)
END IF
TEXT 0,12,0,0
Temp$ = "Communications Settings"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 33:L = 18:B = 49:R = 116
Temp$ = "Baud Rate"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 107:B = 219:R = 112
Temp$ = "Word Length :"+Cr$+""+Cr$+"Stop Bits :"+Cr$+""+Cr$+"Parity :"+Cr$+""+Cr$+"Port :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
Refresh=1:' don't update this window anymore
END IF:' End of CSWIN format
'
LONG IF WINDOW(1) = SNDWIN
LONG IF ColorOn
Red = 0:Green = 0:Blue = 0
CALL RGBFORECOLOR(Red)
Red =-1:Green =-1:Blue =-1
CALL RGBBACKCOLOR(Red)
END IF
TEXT 0,12,,0
T = 8:L = 76:B = 24:R = 148
Temp$ = "Filename : "
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 44:L = 35:B = 60:R = 145
Temp$ = " Bytes Sent :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 64:L = 61:B = 80:R = 146
Temp$ = "File Format :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 84:L = 6:B = 100:R = 147
Temp$ = "Transmission Errors :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
GOSUB "Show_Error"
T = 111:L = 93:B = 127:R = 146
Temp$ = "Status :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
L = 150:R = 282
Temp$ = "Waiting for Start"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 131:L = 78:B = 147:R = 145
Temp$ = "File Type :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 151:L = 58:B = 167
Temp$ = "File Creator :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
GOSUB "Show_CreatorType":' show what type and creator we are sending
GOSUB "Show_Name":' show the name of the file we are going to send
END IF:' END Of SNDWIN Format
'
LONG IF WINDOW(1) = RECWIN
LONG IF ColorOn
Red = 0:Green = 0:Blue = 0
CALL RGBFORECOLOR(Red)
Red =-1:Green =-1:Blue =-1
CALL RGBBACKCOLOR(Red)
END IF
TEXT 0,12,,0
T = 8:L = 76:B = 24:R = 148
Temp$ = "Filename : "
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 44:L = 35:B = 60:R = 145
Temp$ = "Bytes Received :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 64:L = 61:B = 80:R = 146
Temp$ = "File Format :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 84:L = 6:B = 100:R = 147
Temp$ = "Transmission Errors :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
GOSUB "Show_Error"
T = 111:L = 93:B = 127:R = 146
Temp$ = "Status :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
L = 150:R = 282
Temp$ = "Waiting for SOH"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 131:L = 78:B = 147:R = 145
Temp$ = "File Type :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 151:L = 58:B = 167
Temp$ = "File Creator :"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
END IF:' End of RECWIN format
'
LONG IF WINDOW(1) = PROSET AND Refresh=0
T = 3:L = 115:B = 27:R = 242
LONG IF ColorOn
Red = 0:Green = 0:Blue = 0
CALL RGBFORECOLOR(Red)
Red =-1:Green =-1:Blue =-1
CALL RGBBACKCOLOR(Red)
END IF
CALL PENNORMAL:' If you haven't installed the proper
DEF SHADOWBOX(T):' ZMover library-this won't work
T = 6:L = 120:B = 22:R = 241
TEXT 0,12,0,0
Temp$ = "Protocol Settings"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 34:L = 5:B = 50:R = 236
Temp$ = "Default Type/Creator text files..."
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 87:L = 8:B = 103:R = 239
Temp$ = "Default Xmodem File Transfer"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 80:L = 2:B = 80:R = 372
PEN 1,1,1,8,0
CALL MOVETO(L,T):CALL LINETO(R,B)
T = 125:L = 296:B = 153:R = 366
FN FrameBtn("OK")
END IF:' End of PROSET format
'
LONG IF WINDOW(1) = ABTWIN
T = 15:L = 20:B = 31:R = 216
LONG IF ColorOn
Red = 0:Green = 0:Blue = 0
CALL RGBFORECOLOR(Red)
Red =-1:Green =-1:Blue =-1
CALL RGBBACKCOLOR(Red)
END IF
TEXT 0,12,0,0
Temp$ = "BTerm"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 81:L = 27:B = 129:R = 398
Temp$ = "BTerm - A Simple Terminal Program written entirely with ZBasic 5.01"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 144:L = 23:B = 192:R = 393
TEXT 3,,,0
Temp$ = "BTerm Copyright 1991 by Mel Patrick"
CALL TEXTBOX(VARPTR(Temp$)+1,LEN(Temp$),T, 0)
T = 220:L = 340:B = 248:R = 414
FN FrameBtn("OK")
END IF:' End of ABTWIN format
'
'
TEXT TxFont,TxSize,TxFace,TxMode:' Restore the font specs
'
CALL SETPENSTATE(PenSpecs$):' Restore the pen
'
LONG IF ColorOn
CALL RGBFORECOLOR(RFore):' Restore the foreground color
CALL RGBBACKCOLOR(RBack):' Restore the background color
END IF
'
RETURN
'”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’’
'““‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘
"Capture"
'”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’’
'““‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘
LONG IF WINDOW(0) = TSWIN
' <-- Insert WINDOW 2 capture routines here
END IF
'
LONG IF WINDOW(0) = CSWIN
' <-- Insert WINDOW 3 capture routines here
END IF
'
LONG IF WINDOW(0) = SNDWIN
' <-- Insert WINDOW 4 capture routines here
END IF
RETURN
'
LONG IF WINDOW(0) = RECWIN
' <-- Insert WINDOW 5 capture routines here
END IF
RETURN
'
LONG IF WINDOW(0) = PROSET
' <-- Insert WINDOW 6 capture routines here
END IF
'
LONG IF WINDOW(0) = ABTWIN
' <-- Insert WINDOW 7 capture routines here
END IF
RETURN
'”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’’
'““‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘
"Initialize"
'”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’”’’
'““‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘“‘
FN Push(COMWIN):' Push first window on to stack
FN Push(OpenEvent):' Tell my event manager to open the window
APPLE MENU="About BTerm"
'
FileMenu&=FN GETMENU(128):' gets the file menu from resource file
CALL INSERTMENU(FileMenu&,0)
SetMenu&=FN GETMENU(129):' gets the settings menu
CALL INSERTMENU(SetMenu&,0)
ProMenu&=FN GETMENU(130):' gets the transfer menu
CALL INSERTMENU(ProMenu&,0)
'
LONG IF FN CheckColor
' Get a handle to the menu color table
Hndl& = FN GETRESOURCE(CVI("mctb"),1000)
OSErr=FN HLOCK(Hndl&):' Lock it
Ptr&=PEEK LONG(Hndl&):' Get a pointer to the block
Cnt=PEEK WORD(Ptr&):' First word is item count
Ptr&=Ptr&+2:' Move pointer past count
CALL SETMCENTRIES(Cnt,Ptr&):' Set the entries
OSErr=FN HUNLOCK(Hndl&):' Unlock the block
CALL RELEASERESOURCE(Hndl&):' Free up mem
END IF
CALL DRAWMENUBAR:' Redraw the bar
RETURN
'